package org.eclipse.ea.requisit.manager.utils;


import java.util.Comparator;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ImportDeclaration;

public class ImportDeclarationComparator implements
		Comparator<ImportDeclaration> {
	
	private CompilationUnit parser;
	
	public ImportDeclarationComparator(CompilationUnit parser) {
		super();
		this.parser = parser;
	}

	@Override
	public int compare(ImportDeclaration import1, ImportDeclaration import2) {
		
		int line1 = parser.getLineNumber(import1.getStartPosition());
		int line2 = parser.getLineNumber(import2.getStartPosition());
		
		if(line1 < line2){
			return 1;
		}
		
		if(line1 > line2){
			return -1;
		}
		
		return 0;
	}

}
